<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt"  uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />

    <title>布调衣致</title>
    <link href="${pageContext.request.contextPath }/phone/css/main.css" rel="stylesheet" />
    <link href="${pageContext.request.contextPath }/phone/css/font/iconfont.css" rel="stylesheet" />

</head>
<body>

    <div>
        <!--首页的标题栏-->
        <div class="topBar">
            <div class="topmid">
                <button class="search-btn" onclick="search()"></button>
                <form id="formSearch">
                <div class="searchbox-wrap-img" id="serpic">
                    <div class="searchbox-box-img"><img id="preview" alt="" name="pic" src="/bdyz/phone/img/shiyijian.jpg"></div>
                    <span class="serimg-close" id="serimg-close">X</span>
                </div>
                <input name="key" id="key" class="search-input" placeholder="<spring:message code="patternSearch"></spring:message>" type="text" />
                <i class="Hui-iconfont Hui-iconfont-zhaoxiangji ri" onclick="searchImg()"></i>
                <input type="file" name="file" id="file" onchange="uploadImg()">
                <input type="hidden" id="imgData" name="filePath"/>
                </form>
            </div>
            
           <c:choose>
            <c:when test="${language=='zh_cn'}">
            <div class="topright" style="background-image: url(${pageContext.request.contextPath }/phone/img/language.jpg);"><a onclick="changeLanguage('${pageContext.request.contextPath }/api/main/changeLanguage')" href="javascript:void(0)"></a></div>
            </c:when>
             <c:when test="${language=='en'}">
            <div class="topright" style="background-image: url(${pageContext.request.contextPath }/phone/img/language2.jpg);"><a onclick="changeLanguage('${pageContext.request.contextPath }/api/main/changeLanguage')" href="javascript:void(0)"></a></div>
            </c:when>
            <c:otherwise>
             <div class="topright" style="background-image: url(${pageContext.request.contextPath }/phone/img/language.jpg);"><a onclick="changeLanguage('${pageContext.request.contextPath }/api/main/changeLanguage')" href="javascript:void(0)"></a></div>
            </c:otherwise>
            </c:choose>
            <div class="clr"></div>
        </div>
   </div>
    <script src="${pageContext.request.contextPath }/phone/js/jquery-1.8.3.min.js"></script>
    <script src="${pageContext.request.contextPath }/phone/js/ajaxfileupload.js"></script>
    <script type="text/javascript">
    function searchImg(){
		$("input[id=file]").click();
	}
	function uploadImg(){
		$.ajaxFileUpload({
	            url: '${pageContext.request.contextPath }/upload/upload', //用于文件上传的服务器端请求地址
	            secureuri: false, //是否需要安全协议，一般设置为false
	            type: 'post',
	            fileElementId: 'file', //文件上传域的ID
	            dataType: 'json', //返回值类型 一般设置为json
	            success: function (data, status)  //服务器成功响应处理函数
	            {	            	
	            	$("#preview").attr("src",'${pageContext.request.contextPath }/upload/'+data.trim());	
	            	$("#imgData").val('/upload/'+data.trim());   
		        	$("#serpic").show();
		        	$("#key").val("");
			        $("#serimg-close").click(function(){
						 $("#preview").removeAttr("src");
						 $("#imgData").val("");   
						 $(this).parent().hide();
						 $(".topBar .topmid input[type=text]").css("width","80%");
					 });
					 $(".topBar .topmid input[type=text]").css("width","60%");
	            }
	           
	        });	
	 }
		
    function changeLanguage(baseUrl){
		$.ajax({
			async:false,
			url:baseUrl,
			type:'post',
			success:function(result){
				var status=result.msg.status;
				if(status==0){
					location.reload();
				}
			}
		});
	}
    
    /* 图片搜索 */
    function search()
    {  	  		 
	  	
	  	 if( $("#imgData").val()!=""&&$("#imgData").val()!=null)
	  	 {    
	  		 $("#formSearch").attr('action','${pageContext.request.contextPath }/api/patternfilter/flowertypecatalog1');
	  		 $("#formSearch").submit();
	  	 }
	  	 else
	  	 {   		
	  		 if($("#key").val()!=""&&$("#key").val()!=null)
	  		 {    
	  			 $("#formSearch").attr('action','${pageContext.request.contextPath }/api/patternfilter/flowertypecatalog1');
	  			 $("#formSearch").submit();
	  		 }   
	  		 else
	  		 {
	  			layer.open({
				    content: '<spring:message code="head.enterSearchKeyword"></spring:message>'
				    ,skin: 'msg'
				    ,time: 1 //1秒后自动关闭
				  });
	  			 return false;
	  		 }
	  	 }    	
    }
    </script>
</body>
</html>
